package com.zyh.service.impl;

import com.zyh.dao.UserDao;
import com.zyh.pojo.User;
import com.zyh.service.UserService;
import com.zyh.util.SaltUtil;
import org.apache.shiro.crypto.hash.Md5Hash;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl implements UserService {
    @Autowired
    UserDao userDao;
    @Override
    public User findByName(String username) throws Exception{
        return userDao.findByName(username);
    }

    @Override
    public void save(String username, String password) {
        String salt=SaltUtil.getSalt(8);
        Md5Hash md5Hash = new Md5Hash(password,salt,1024);
        password=md5Hash.toHex();
        userDao.save(username,password,salt);
    }

    @Override
    public User findById(Integer id) {
        return userDao.findById(id);
    }

    @Override
    public List<User> findAllUserName() {
        return userDao.findAllUserName();
    }
}
